let isToday = (date: Date) => {
  date = new Date(date)
  const today = new Date()
  return today.getFullYear() === date.getFullYear() && today.getMonth() === date.getMonth() &&
    today.getDate() === date.getDate()
}

//yyyy年MM月dd日 HH时mm分ss秒
let format = (date: Date, formatStr: string) => {
  date = new Date(date)

  let y = date.getFullYear().toString()
  let mo = date.getMonth().toString()
  let d = date.getDate().toString()
  let h = date.getHours().toString()
  let mi = date.getMinutes().toString()
  let s = date.getSeconds().toString()
  let ms = date.getMilliseconds().toString()

  let formatDate = formatStr.replace('yyyy', y.toString())
    .replace('MM', mo.padStart(2, '0'))
    .replace('M', mo)
    .replace('dd', d.padStart(2, '0'))
    .replace('d', d)
    .replace('HH', h.padStart(2, '0'))
    .replace('H', h)
    .replace('mm', mi.padStart(2, '0'))
    .replace('ss', s.padStart(2, '0'))
    .replace('ms', ms.padStart(3, '0'))
    .replace('m', mi)

  return formatDate
}

export const dateUtils = { isToday, format }